<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>Document</title>
  <style>
    .box1{width:300px;height: 300px;background: red;margin:50px;overflow: hidden;}
    .box2{width:200px;height: 200px;background: green;margin: 50px;overflow: hidden;}
    .box3{width:100px;height: 100px;background: blue;margin: 50px;}
  </style>
</head>
<body>
  <div class="box1">
    <div class="box2">
      <div class="box3"></div>
    </div>
  </div>
</body>
<script>
  var box1 = document.querySelector(".box1")
  var box2 = document.querySelector(".box2")
  var box3 = document.querySelector(".box3")

  box1.onclick = function(){
    console.log("冒泡的red");
  }
  box2.onclick = function(eve){
    var e = eve || window.event;
    stopBubble(e);
    console.log("冒泡的green");
  }
  box3.onclick = function(eve){
    var e = eve || window.event;

    stopBubble(e);

    // e.cancelBubble = true;
    // e.stopPropagation();


    console.log("冒泡的blue");
  }

  function stopBubble(e){
    if(e.stopPropagation){
      e.stopPropagation();
    }else{
      e.cancelBubble = true;
    }
  }

  // box1.addEventListener("click", function(){
  //   console.log("冒泡的red")
  // }, false);
  // box2.addEventListener("click", function(){
  //   console.log("冒泡的green")
  // }, false);
  // box3.addEventListener("click", function(){
  //   console.log("冒泡的blue")
  // }, false);

  // box1.addEventListener("click", function(){
  //   console.log("捕获的red")
  // }, true);
  // box2.addEventListener("click", function(){
  //   console.log("捕获的green")
  // }, true);
  // box3.addEventListener("click", function(){
  //   console.log("捕获的blue")
  // }, true);

  // document.addEventListener("click", function(){
  //   console.log("冒泡的document")
  // }, false)
  // document.addEventListener("click", function(){
  //   console.log("捕获的document")
  // }, true)

</script>
</html>